<cfparam name="view" type="string" default="userType" />
<cfparam name="action" type="string" default="" />
<cfparam name="error" type="string" default="" />
<cfparam name="clientType" type="string" default="" />
<!--- wrapperCode + mode go to confirm --->
<cfparam name="wrapperCode" type="string" default="" />
<cfparam name="mode" type="string" default="live" />
<!--- workshopID go to wrapper --->
<cfparam name="workshopID" type="numeric" default="0" />

<cfif cgi.HTTPS eq "off" AND (cgi.HTTP_HOST eq "calgrants.org" OR cgi.HTTP_HOST eq "www.calgrants.org")>
	<cflocation url="https://www.calgrants.org/wrapper/?#cgi.QUERY_STRING#" addtoken="No">
</cfif>

<cfif workshopID gt 0>
	<cfset view = "wrapper" />
<cfelseif Len(Trim(wrapperCode)) gt 0>
	<cfset action = "validateWrapperCode" />
<cfelse>
	<cfset view = "wrapperCode" />
</cfif>

<cfswitch expression="#action#">
	<cfcase value="validateWrapperCode">
		<cfscript>
			workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
			workshop = workshopGateway.query(Evaluation_Code = wrapperCode);
			if (workshop.RecordCount eq 0 OR workshop.Deleted eq 1) {
				error = "The wrapper code is invalid";
				view = "wrapperCode";
			} else if (workshop.RecordCount gt 1) {
				error = "The wrapper code you entered is valid, however there is conflict with another workshop.\n\nPlease contact #request.personality.name# at #request.personality.email#.";
				view = "wrapperCode";
			} else if (DateFormat(workshop.Workshop_Date, "yyyymmdd") gt DateFormat(Now(), "yyyymmdd") and mode eq "live") {
				error = "The wrapper code you entered is valid, however the workshop date is in the future.\n\nThe workshop wrapper can only be launched the day of the workshop.";
				view = "wrapperCode";
			} else if (DateFormat(workshop.Workshop_Date, "yyyymmdd") lt DateFormat(Now(), "yyyymmdd") and mode eq "live") {
				error = "The wrapper code you entered is valid, however the workshop date is in the past.\n\nThe workshop wrapper can only be launched the day of the workshop.";
				view = "wrapperCode";
				// live wrapper can only be launched for undeleted, approved
			} else if (workshop.Approved eq 0 AND mode eq "live") {
				error = "The wrapper code you entered is valid, however the workshop is not approved.\n\nThe workshop wrapper can only be launched for approved workshops.";
				view = "wrapperCode";
			} else {
				view = "confirmWorkshop";
			}
		</cfscript>
	</cfcase>
</cfswitch>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Cash for College Workshop Wrapper</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Cash for College Workshop Wrapper">
	<meta name="author" content="Syntric">
	<cfoutput>
		<script src="#request.pathToJQuery#" type="text/javascript"></script>
		<script src="#request.pathToBootstrap#" type="text/javascript"></script>
		<link href="#request.pathToBootstrapCSS#" rel="stylesheet" />
		<link href="#request.pathToUI#/common.css" rel="stylesheet" />
		<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet" type="text/css" />
		<cfif view eq "wrapper">
			<script type="text/javascript" src="/assets/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
			<link rel="stylesheet" href="/assets/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
			<link rel="stylesheet" href="/assets/fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" type="text/css" media="screen" />
			<script type="text/javascript" src="/assets/fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
		</cfif>
		<cfif Len(Trim(error)) gt 0>
			<script type="text/javascript">
				alert("#error#");
			</script>
		</cfif>
	</cfoutput>
	<script type="text/javascript">
	<!--
		<cfoutput>
            var workshopID = #workshopID#;
			var clientType = "#clientType#";
			var mode = "#mode#";
		</cfoutput>
		var goTo = function(app) {
			if (app === "fafsa") {
				//loc = "goToFAFSA.cfm";
				loc = "https://fafsa.ed.gov"
			} else if (app === "chafee") {
        		//loc = "goToChafee.cfm";
				loc = "https://www.chafee.csac.ca.gov/StudentApplication.aspx";
			} else if (app === "dreamAct") {
        		//loc = "goToCADreamAct.cfm";
				loc = "https://dream.csac.ca.gov/";
			} else if (app === "exitSurvey") {
        		//loc = "goToExitSurvey.cfm?workshopID=" + workshopID + "&clientType=" + clientType + "&mode=" + mode;
				loc = "https://www.calgrants.org/wrapper/exitSurvey.cfm?workshopID=" + workshopID + "&clientType=" + clientType + "&mode=" + mode;
			} else {
				window.alert("Invalid selection");
				return;
			}
			window.open(loc, "_new", "height=600,width=850,left=50,top=50,titlebar=yes,toolbar=no,location=no,resizable=yes,menubar=no,fullscreen=no,channelmode=no,status=no,scrollbars=yes", true);
        };
		var toggleMode = function() {
			//console.log($("#clientType"));
			var clientType = $("#clientType option:selected")[0].value;
			console.log(clientType);
			// clientType = organizer or attendee
			/*var clientType = clientType || "organizer";*/
			if (clientType === "organizer") {
				$("#modeContainer").show();
			} else {
				$("#modeContainer").hide();
				$("#mode").val("live");
			}
		}
		var testWindowSize = function() {
			if ($(window).width() != screen.width) {
				window.alert("Please maximize the browser window and press F11 to go to full screen mode");
			}
		};
		/*var renderPopups = function () {
            $(".fbox").fancybox({
                fitToView: true,
                width: "100%",
                height: "100%",
                autoSize: false,
                closeClick: false,
                openEffect: "none",
                closeEffect: "none",
                beforeLoad: function () {
                    var footer;
                    var footerId = $(this.element).data("title-id");
                    if (footerId) {
                        footer = $("#" + footerId);
                        if (footer.length) {
                            this.title = footer.html();
                        }
                    }
                }
            });
        };*/
		var warnOnClose = function(e) {
			alert("Please do not close this window.  Select \"Stay on Page\" when the next dialog appears");
			e.preventDefault();
		};
		$(function() {
			testWindowSize();
			//if ($(".fbox").length > 0) {
				//renderPopups();
				/*$(window).on("beforeunload", function(e) {
					alert("Do not close this window.\n\nSelect \"Stay on this Page\" when the next dialog appears.");
					e.preventDefault();
					return "Do not close this window. Select \"Stay on this Page\".";
				});*/
			//}
		});
	//-->
	</script>
	<style type="text/css">
		.main-well {
			background-color: white;
		}
		.sub-well {
			margin-top: 20px;
			margin-bottom: 40px;
			margin-left: 20px;
			margin-right: 20px;
		}
		p.step {
			font-size: 1.2em;
			line-height: 1.4em;
		}
	</style>
</head>
<body style="margin-top: 20px;">
	<cfoutput>
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<table border="0" cellpadding="0" cellspacing="0">
						<tr valign="bottom">
							<td>
								<img src="../wrapper/images/Cash_for_College_logo.gif" width="204" height="54" alt="Cash for College">
							</td>
							<cfif mode eq "practice">
								<td style="padding-left: 20px; padding-bottom: 5px;">
									<span style="font-weight: bold; color: red;">Practice Mode</span>
								</td>
							</cfif>
						</tr>
						<tr>
							<td colspan="2">&nbsp;<br /></td>
						</tr>
					</table>
				</div>
			</div>
			<div class="row-fluid">
				<div class="span12">
					<cfif view eq "confirmWorkshop">
						<!--- confirm requires wrapperCode + mode --->
						<cfscript>
							workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
							workshop = workshopGateway.query(Evaluation_Code = wrapperCode);
						</cfscript>
						<cfif workshop.RecordCount gt 0>
							<cfform id="confirmForm" name="confirmForm" action="#script_name#" method="post">
								<cfinput type="hidden" name="workshopID" value="#workshop.Workshop_ID#" />
								<cfinput type="hidden" name="clientType" value="#clientType#" />
								<cfinput type="hidden" name="mode" value="#mode#" />
								<div class="well well-large main-well">
									<h2>Confirm Workshop</h2>
									<h3>Confirm the following workshop information</h3>
									<p>
										<strong>#workshop.Site#</strong><br />
										#DateFormat(workshop.Workshop_Date, "dddd, mmmm d, yyyy")# #TimeFormat(workshop.Start_Time, "h:mmtt")#-#TimeFormat(workshop.End_Time, "h:mmtt")#<br />
										#workshop.Address#<br />
										#workshop.City#, CA #workshop.Zip_Code#
									</p>
									<p>
										<strong>Site Contact</strong><br>
										#workshop.Manager_Full_Name#<br />
										#workshop.Manager_Phone#<cfif Len(Trim(workshop.Manager_Extension)) gt 0> x #workshop.Manager_Extension#</cfif><br />
										#workshop.Manager_Email#
									</p>
									<p>
										<button name="confirmButton" value="Confirm" class="btn btn-primary">Confirm</button>&nbsp;<a href="#script_name#" class="btn btn-primary">Start Over</a>
									</p>
								</div>
							</cfform>
						<cfelse>
							<div class="well well-large main-well">
								<h2>Workshop Not Found</h2>
								<h3>No workshops were found with the wrapper code provided</h3>
								<p><a href="#script_name#" class="btn btn-primary btn-large">Start Over</a></p>
							</div>
						</cfif>
					<cfelseif view eq "wrapper">
						<!--- wrapper requires workshopID --->
						<cfscript>
							workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
							workshop = workshopGateway.get(Workshop_ID = workshopID);
							siteGateway = new assets.calgrants.com.gateway.SiteGateway();
							site = siteGateway.get(Site_ID = workshop.getSite_ID());
						</cfscript>
						<div class="well well-large main-well">
							<h3>#site.getSite()#</h3>
							<div class="row-fluid">
								<div class="span4">
									<div class="well well-large sub-well">
										<h3>Foster Youth Students</h3>
                  						<p class="step"><strong>Step 1</strong> Submit your FAFSA online.</p>
										<p><a class="btn btn-primary btn-large btn-block" onclick="alert('When you are finished with the FAFSA please close the window to return to this page.'); goTo('fafsa'); return false;">Go to the FAFSA</a></p>
                					    <p class="step"><strong>Step 2</strong> Submit your Chafee application online.</p>
										<p><a class="btn btn-primary btn-large btn-block" onclick="alert('When you are finished with the Chafee Application please close the window to return to this page.'); goTo('chafee'); return false;">Go to the Chafee Application</a></p>
                    					<p class="step"><strong>Step 3</strong> Complete our exit survey to qualify for our scholarship.</p>
                						<p><a class="btn btn-primary btn-large btn-block" onclick="alert('When you are finished with the exit survey please close the window to return to this page.'); goTo('exitSurvey'); return false;">Complete the exit survey</a></p>
									</div>
								</div>
								<div class="span4">
									<div class="well well-large sub-well">
										<h3>General Students</h3>
										<p class="step"><strong>Step 1</strong> Submit your FAFSA online.</p>
										<p><a class="btn btn-primary btn-large btn-block" onclick="alert('When you are finished with the FAFSA please close the window to return to this page.'); goTo('fafsa'); return false;">Go to the FAFSA</a></p>
										<p class="step"><strong>Step 2</strong> Complete our exit survey to qualify for our scholarship.</p>
										<p><a class="btn btn-primary btn-large btn-block" onclick="alert('When you are finished with the exit survey please close the window to return to this page.'); goTo('exitSurvey'); return false;">Complete the exit survey</a></p>
									</div>
								</div>
								<div class="span4">
									<div class="well well-large sub-well">
										<h3>CA Dream Act/AB540 Students</h3>
										<p class="step"><strong>Step 1</strong> Submit your CA Dream Act application online.</p>
										<p><a class="btn btn-primary btn-large btn-block" onclick="alert('When you are finished with the CA Dream Act application please close the window to return to this page.'); goTo('dreamAct'); return false;">Go to the CA Dream Act application</a></p>
										<p class="step"><strong>Step 2</strong> Complete our exit survey to qualify for our scholarship.</p>
										<p><a class="btn btn-primary btn-large btn-block" onclick="alert('When you are finished with the exit survey please close the window to return to this page.'); goTo('exitSurvey'); return false;">Complete the exit survey</a></p>
									</div>
								</div>
							</div>
						</div>
					<cfelseif view eq "wrapperCode">
						<div class="well well-large main-well">
							<h2>Cash for College Workshop Wrapper</h2>
							<!--- <h3>Press F11 to go to full screen mode</h3> --->
							<cfform id="wrapperCodeForm" name="wrapperCodeForm" action="#script_name#" method="post">
								<cfinput type="hidden" name="action" value="validateWrapperCode" />
								<div>
									<label>Are you a workshop attendee or organizer?</label>
									<cfselect name="clientType" required="yes" message="Are you a workshop attendee or organizer is required" onChange="toggleMode()">
										<option value="attendee" selected>Attendee</option>
										<option value="organizer">Organizer</option>
									</cfselect>
								</div>
								<div id="modeContainer" style="display: none;">
									<label>Mode</label>
									<cfselect name="mode" required="yes" message="Mode is required">
										<option value="live" selected>Live</option>
										<option value="practice">Practice</option>
									</cfselect>
								</div>
								<div>
									<label>Wrapper Code</label>
									<cfinput type="text" name="wrapperCode" value="#wrapperCode#" required="yes" message="Wrapper Code is required" maxlength="10" />
								</div>
								<p><cfinput type="submit" id="nextButton" name="nextButton" value="Next" class="btn btn-primary" /></p>
							</cfform>
							<p>Need help? Contact #request.personality.name# at <a href="mailto:#request.personality.email#">#request.personality.email#</a> or 916-712-0743. For technical assistance contact #request.developer.name# at <a href="mailto:#request.developer.email#">#request.developer.email#</a> or #request.developer.phone#.</p>
						</div>
					</cfif>
				</div>
			</div>
		</div>
	</cfoutput>
</body>
</html>